<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*"%>
<%@ page import="oracle.jdbc.pool.OracleDataSource"%>

<!-- Database lookup -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
<title>Displaying product details</title>
</head>
<body>
<BR>
<BR>
<H1>Here are the details of the product you selected</H1>
<BR>
<BR>
<%
Connection conn = null;
ResultSet rset = null;
String error_msg = "";
String ID = request.getParameter("prodID").toString();
ID=ID.trim();


try {
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:ab3416/kFxJssQk@//w4111b.cs.columbia.edu:1521/ADB");
conn=(Connection) request.getSession().getAttribute("Connection");
if (conn == null) {
	conn = ods.getConnection();
	request.getSession().setAttribute("Connection", conn);
}
//request.getSession().setAttribute("custID", "39daisy");
//String ID = (String)(request.getSession().getAttribute("ID"));
//String ID = request.getParameter("pid").toString();
//String ID = "CP005";
Statement stmt = conn.createStatement();
request.getSession().setAttribute("ID", ID);
rset = stmt.executeQuery("select decode(category, 'T','Tops','P','Pants','O','Others') as type, description, brand, price from clothes c, products p where  p.pid = c.pid and p.pid = '" + ID + "'");
response.setContentType("text/html");
} catch (SQLException e) {
error_msg = e.getMessage();
//if( conn != null ) {
//conn.close();
//}
}
%>

<H3>
<TABLE>
<%
if(rset != null) {
while(rset.next()) {
out.print("<tr>");
out.print("Type : " + rset.getString("type") + "<BR>");
out.print("</tr>");
out.print("<tr>");
out.print("Description : " + rset.getString("description") + "<BR>");
out.print("</tr>");
out.print("<tr>");
out.print("Brand : " + rset.getString("brand") + "<BR>");
out.print("</tr>");
out.print("<tr>");
out.print("Price : $" + rset.getString("price") + "<BR>");
out.print("</tr>");
}
} else {
out.print(error_msg);
}
//if( conn != null ) {
//conn.close();
//}
%>
</TABLE>
</H3>

<% 
try {
	OracleDataSource ods = new OracleDataSource();
	ods.setURL("jdbc:oracle:thin:ab3416/kFxJssQk@//w4111b.cs.columbia.edu:1521/ADB");
	conn=(Connection) request.getSession().getAttribute("Connection");
	if (conn == null) {
		conn = ods.getConnection();
		request.getSession().setAttribute("Connection", conn);
	}
	Statement stmt = conn.createStatement();
	rset = stmt.executeQuery("select description, isbn, author, publisher, published_date, edition, price " +
		"from books b, products p where  p.pid = b.pid and p.pid = '" + ID + "'");
	response.setContentType("text/html");
}
catch(SQLException e) {
	error_msg = e.getMessage();
}

%>

<H3>
<TABLE>
<%
if(rset != null) {
while(rset.next()) {
	out.print("<tr>");
	out.print("Description : " + rset.getString("description") + "<BR>");
	out.print("</tr>");
	out.print("<tr>");
	out.print("ISBN : " + rset.getString("isbn") + "<BR>");
	out.print("</tr>");
	out.print("<tr>");
	out.print("Author : " + rset.getString("author") + "<BR>");
	out.print("</tr>");
	out.print("<tr>");
	out.print("Publisher : " + rset.getString("publisher") + "<BR>");
	out.print("</tr>");
	out.print("<tr>");
	out.print("Published Date : " + rset.getString("published_date") + "<BR>");
	out.print("</tr>");
	out.print("<tr>");
	out.print("Edition : $" + rset.getString("edition") + "<BR>");
	out.print("</tr>");
	out.print("<tr>");
	out.print("Price : $" + rset.getString("price") + "<BR>");
	out.print("</tr>");
}
} else {
out.print(error_msg);
}
//if( conn != null ) {
//conn.close();
//}
%>
</TABLE>
</H3>


<form name='ProdDetailsForm' action='DisplayDetailsServlet'>
<br> <h3> Enter Quantity Required : <input type='text' id = 'Enter Quantity Required : ' name='qty'> </h3>
<br><br><input type='submit' value='Purchase'></br>
</form>


  <div id="nav-top" align="right">
    <ul>
    
      <li><a href="Logout.jsp">Logout</a> |</li>
      <!--  <li><a href="Account.jsp">My Account</a> |</li> -->
      <li><a href="Contact.jsp">Contact us</a></li>
    </ul>
  </div>




</body>
</html>